import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gold/app/user_provider.dart';
import 'package:gold/widgets/http_image.dart';
import 'package:provider/provider.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:gold/base/provider_scaffold.dart';
import 'package:gold/ui/my/invite/invite_viewmodel.dart';
import 'package:gold/utils/res.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description: 我要赚钱
/// @author tangzhentao
/// @created at 14:57 2024/11/30

class InvitePage extends StatelessWidget {
  const InvitePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(image: DecorationImage(image: AssetImage(Res.imagesInviteBg), fit: BoxFit.cover)),
      child: ProviderScaffold<InviteViewModel>(
        model: InviteViewModel(),
        backgroundColor: XfgColor.transparent,
        appBar: (ctx) =>  xfgAppbar(title: '我要赚钱', systemOverlayStyle: SystemUiOverlayStyle.light, backgroundColor: XfgColor.transparent),
        builder: (ctx, invite) => SingleChildScrollView(
          child: Column(
            children: [
              SizedBox(height: XfgSize().size22),
              XfgText('邀请好友加入先锋金', fontSize: XfgSize().text24, color: XfgColor.inviteTitle, bold: FontWeight.bold),
              SizedBox(height: XfgSize().size16),
              XfgText('你与好友都可获得66积分', fontSize: XfgSize().text14, color: XfgColor.inviteTitle),
              RepaintBoundary(
                key: invite.saveKey,
                child: Container(
                  margin: EdgeInsets.only(top: XfgSize().size24, bottom: XfgSize().size16),
                  height: XfgSize().size439,
                  width: XfgSize().size355,
                  child: Stack(
                    children: [
                      Align(
                        alignment: Alignment.bottomCenter,
                        child: Container(
                          height: XfgSize().size393,
                          decoration: BoxDecoration(color: XfgColor.white, borderRadius: BorderRadius.circular(XfgSize().size6)),
                          padding: EdgeInsets.only(bottom: XfgSize().size52),
                          alignment: Alignment.bottomCenter,
                          child: Container(
                            width: XfgSize().size224,
                            height: XfgSize().size206,
                            decoration: const BoxDecoration(image: DecorationImage(image: AssetImage(Res.imagesInviteCode))),
                            alignment: Alignment.center,
                            child: QrImageView(data: '策划似乎is家吉林省', size: XfgSize().size160),
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topCenter,
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            HttpImage(ctx.read<UserProvider>().user.avatar, size: Size.square(XfgSize().size107), radius: BorderRadius.circular(XfgSize().size107), placeholder: Res.imagesAvatar),
                            SizedBox(height: XfgSize().size12),
                            XfgText('梦想家', fontSize: XfgSize().text18, color: XfgColor.text1, bold: FontWeight.bold)
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton(
                    onPressed: invite.save,
                    style: ButtonStyle(
                        backgroundColor: WidgetStatePropertyAll(XfgColor.text1D.withValues(alpha: 0.5)),
                        shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(XfgSize().size45))),
                        fixedSize: WidgetStatePropertyAll(Size(XfgSize().size120, XfgSize().size45))
                    ),
                    child: XfgText('保存图片', fontSize: XfgSize().text16, color: XfgColor.white),
                  ),
                  SizedBox(width: XfgSize().size26),
                  TextButton(
                    onPressed: invite.invite,
                    style: ButtonStyle(
                        backgroundColor: const WidgetStatePropertyAll(XfgColor.theme),
                        shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(XfgSize().size45))),
                        fixedSize: WidgetStatePropertyAll(Size(XfgSize().size199, XfgSize().size45))
                    ),
                    child: XfgText('马上邀请好友', fontSize: XfgSize().text16, color: XfgColor.white),
                  ),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

}
